package org.example;

import cn.hutool.core.annotation.Alias;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Map;

@Data
@NoArgsConstructor
public class Music {

    @Alias(value = "结算期间")
    private String period;

    @Alias(value = "平台")
    private String platform;

    @Alias(value = "类型")
    private String type;

    @Alias(value = "中央曲库歌曲ID")
    private String centreId;

    @Alias(value = "专辑名")
    private String albumTitle;

    @Alias(value = "歌曲名")
    private String songName;

    @Alias(value = "歌曲ISRC")
    private String songNo;

    @Alias(value = "歌手名")
    private String singer;

    @Alias(value = "词作者")
    private String lyricist;

    @Alias(value = "曲作者")
    private String composer;

    @Alias(value = "CP分成收入")
    private BigDecimal money;

    public Music(String period, String platform, String centreId, String albumTitle, String songName, String songNo, String singer, String lyricist, String composer, BigDecimal money) {
        this.period = period;
        this.platform = platform;
        this.centreId = centreId;
        this.albumTitle = albumTitle;
        this.songName = songName;
        this.songNo = songNo;
        this.singer = singer;
        this.lyricist = lyricist;
        this.composer = composer;
        this.money = money;
    }

    public Music(Map<String, Object> data, String fileName) {

        this.platform = data.get("平台").toString();
        if(fileName.indexOf("aiting")>=0){
            this.platform = data.get("平台").toString()+"-"+data.get("渠道商").toString();
        }
        if(fileName.indexOf("song")>=0){
            if(data.get("中央曲库歌曲ID")==null){
                this.centreId = data.get("中央曲库ID").toString();
            }else{
                this.centreId = data.get("中央曲库歌曲ID").toString();
            }

            this.period = data.get("结算期间").toString();
            this.songName = data.get("歌曲名").toString();
            this.type = "歌曲";
        }
        if(fileName.indexOf("mv")>=0){
            this.centreId = data.get("中央曲库MVID").toString();
            this.period = data.get("结算期间").toString();
            this.songName = data.get("MV名").toString();
            this.type = "MV";
        }
        if(fileName.indexOf("single")>=0){
            this.centreId = data.get("中央曲库歌曲ID").toString();
            this.period = data.get("日期").toString();
            this.songName = data.get("歌曲名").toString();
            this.type = "单曲";
        }
        if(data.get("专辑名")!=null){
            this.albumTitle = data.get("专辑名").toString();
        }
        this.songNo = data.get("歌曲ISRC").toString();
        this.singer = data.get("歌手名").toString();
        if(data.get("词作者")!=null){
            this.lyricist = data.get("词作者").toString();
        }
        if(data.get("曲作者")!=null){
            this.composer = data.get("曲作者").toString();
        }

        this.money = BigDecimal.valueOf(Double.parseDouble(data.get("CP分成收入").toString()));
    }

}
